package erfgame.frontend.desktop.view.terrain.iso.interaction;

import java.awt.Point;

import erfgame.core.Point3D;
import erfgame.core.entity.Active;
import erfgame.core.entity.Entity;
import erfgame.core.entity.State;
import erfgame.core.graphics.renderer.RendererContext;
import erfgame.core.path.PathCalculator;
import erfgame.core.world.World;
import erfgame.core.world.WorldContext;
import erfgame.core.world.WorldDAOManager;
import erfgame.core.world.entity.activity.WalkActivity;
import erfgame.core.world.terrain.TerrainUtils;

import erfgame.frontend.desktop.view.terrain.iso.handler.InteractionHandler;

public class WalkInteraction implements Interaction {

	private Entity entity;
	private Point3D to;
	private WorldContext worldContext;
	private long duration;
	private State walkState;
	private PathCalculator pathCalculator;
	private WorldDAOManager worldDAOManager;
	private RendererContext rendererContext;
	
	public WalkInteraction( 
			Entity entity, 
			Point3D to,
			WorldContext worldContext,
			long duration,
			State walkState,
			PathCalculator pathCalculator, 
			WorldDAOManager worldDAOManager, 
			RendererContext rendererContext
	) {
		this.entity = entity;
		this.to = to;
		this.worldContext = worldContext;
		this.duration = duration;
		this.walkState = walkState;
		this.pathCalculator = pathCalculator;
		this.worldDAOManager = worldDAOManager;
		this.rendererContext = rendererContext;
	}
	
	public InteractionHandler activate() {
		// TODO get proper index
		int toIndex = 0;
		World world = worldContext.getCurrentWorld();
		Point gridCoordinates = world.getGridCoordinates(to.x, to.y);
		WalkActivity activity = new WalkActivity(
				entity, 
				gridCoordinates, toIndex, 
				pathCalculator, 
				duration, 
				walkState,
				worldContext, 
				worldDAOManager, 
				rendererContext
		);
		if( activity.start() ) {
			((Active)entity).addActivity(activity);
		}
		return null;
	}

	
}
